home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13332 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  52 lines

  1. Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!usenet
  2. From: grantp@usa.pipeline.com(Pete Grant)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: NEWBIE : Quicksort
  5. Date: 25 Mar 1996 01:12:47 GMT
  6. Organization: Pipeline USA
  7. Message-ID: <4j4ruf$gf4@news1.h1.usa.pipeline.com>
  8. References: <Pine.SOL.3.91.960324135520.8433A-100000@orion>
  9. NNTP-Posting-Host: 38.8.120.9
  10. X-PipeUser: grantp
  11. X-PipeHub: usa.pipeline.com
  12. X-PipeGCOS: (Pete Grant)
  13. X-Newsreader: Pipeline v3.5.0
  14.  
  15. On Mar 24, 1996 14:00:23 in article <NEWBIE : Quicksort>, 'FRANCO
  16. <c2eyf931@sfsu.edu>' wrote: 
  17.  
  18.  
  19. >Hello all....... 
  20. >I need some help. (for those who cares). I need to sort an array of  
  21. >integers using the quicksort algorithm. (using partisioning and recursion)
  22.  
  23. >Can anyone help? 
  24. #include <iostream.h> 
  25. #include <stdlib.h> 
  26.  
  27.  
  28. int comp(const void * a, const void * b) 
  29.  { 
  30.    return (*(int*)a - *(int*)b); 
  31.  } 
  32.  
  33.  
  34. int main () 
  35.  { 
  36.    int z[] = {5,3,7,12,100,32,80,21}; 
  37.    int n = sizeof(z) / sizeof(int); 
  38.    qsort(z, n, sizeof(int), comp); 
  39.    for (int i = 0; i < n; i++) 
  40.       cout << ' ' << z[i]; 
  41.    cout << endl;  
  42.    return 0; 
  43.  } 
  44.  
  45. -- 
  46.  
  47. Pete Grant 
  48. Kalevi, Inc. 
  49. Sofware Engineering
  50.